/*
 *
 *	 Download:
 *  http://www.ritgamedev.com/tutorials/glutEclipse/resources/glutmingw.zip
 *	(or take it from this project)
 *
 *	Put glut32.dll in C:\Wondows\System32 folder
 *	put glut.h in C:\MinGW\include\GL
 *	put libglut32.a in C:\MinGW\lib (if it's not already there)
 *
 *	Make sure to RightClick on the project, select Properties.
 *	Open C/C++ Build -> Settings ->  MinGW Linker -> Libraries
 *	Add the libraries: glut32, glu32, glut, opengl32
 *	Save.
 *
 *
 *
 */
#define GLUT_DISABLE_ATEXIT_HACK

#include "gl/glut.h"
#include <windows.h>
#include <math.h>
#include "Environment.h"
#include <iostream>

const int WIDTH = 600;
const int HEIGHT = 480;

/* Prototypes */
void init();
void display();

/* Definitions */

using namespace std;

/* Initializes the OpenGL state */
void init() {
	glClearColor( 0.0, 0.0, 0.0, 1.0 ); /* Set the clear color */
}

/* Displays a black clear screen */
void display() {
	//First, the ModelViewProjection Matrix is setup
		//this determines how the scene will be viewed
//		float m[] = {	2.0, 0, 0, 0,
//						0, 2.0, 0, 0,
//						0, 0, 2.0, 0,
//						-1.0, -1.0, 0, 3.0};
//		glMatrixMode(GL_MODELVIEW);
//		glLoadIdentity();
//		glMultMatrixf(m);
		glMatrixMode(GL_PROJECTION);
		glLoadIdentity();

		//Second, the framebuffer is filled with the objects in the scene
		glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

		Environment * env = new Environment();
		env->draw();

		glutSwapBuffers();
}


void keyboard (unsigned char key, int x, int y) {
}
void animation()
{

}
void reshape(int w, int h)
{
	if (w == 0 || h == 0) return;

	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluPerspective(60.0, (GLdouble)w/(GLdouble)h, 1.0, 20.0);

	glMatrixMode(GL_MODELVIEW);
	glViewport (0, 0, (GLsizei) w, (GLsizei) h);
}

/* The main function */
int main( int argc, char *argv[] ) {
	glutInit(&argc, argv);
		glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
		glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

		glutInitWindowSize (900, 700);
		glutInitWindowPosition (300, 50);
		glutCreateWindow ("Star Wars Battle");

//		eye = vec3(0,0,8.0);
//		camera.move(eye);
//		camera.moveForward(1.0);
		init();

		// Define callbacks and functions for various tasks.
		glutDisplayFunc(display);
		glutReshapeFunc(reshape) ;
		glutKeyboardFunc(keyboard);
		glutIdleFunc(animation);

		glutMainLoop();
		return 0;
}


